package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;

import javax.swing.JFrame;

import model.kwalificatiebeheer.Criterium;
import model.kwalificatiebeheer.Werkproces;

import view.AddObjectOptionPane;
import view.ComponentenTableModel;
import view.ViewCriteriumPanel;

public class ViewCriteriumActions implements MouseListener, ActionListener {

	ViewCriteriumPanel sender;
	
	public ViewCriteriumActions(ViewCriteriumPanel sender){
		this.sender = sender;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("btnSave")){
			sender.getCriterium().setComponenten(sender.getComponentsCriterium());
			sender.getCriterium().setPrestatieIndicator(sender.getTxtPrestatieIndicator().getText());
			JFrame f = (JFrame) sender.getTopLevelAncestor();
			f.dispose();
		}else if(e.getActionCommand().equals("addComp")){
			ArrayList<String> comps = sender.getComponentsCriterium();
			AddObjectOptionPane ap = new AddObjectOptionPane("Component");
			if(ap.getResults().size() > 0){
				comps.add(ap.getResults().get("title"));
			}
			sender.getTblComponents().setModel(new ComponentenTableModel(comps));
		}else if(e.getActionCommand().equals("deleteComp")){
			ArrayList<String> comps = sender.getComponentsCriterium();
			comps.remove(sender.getActiveComponent());
			sender.getTblComponents().setModel(new ComponentenTableModel(comps));
		}
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		int row = sender.getTblComponents().getSelectedRow();
		String com = sender.getComponentsCriterium().get(row);
		sender.setActiveComponent(com);
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {}
	@Override
	public void mouseExited(MouseEvent arg0) {}
	@Override
	public void mousePressed(MouseEvent arg0) {}
	@Override
	public void mouseReleased(MouseEvent arg0) {}
}
